package com.lxy.code.service.impl;

import cn.hutool.extra.mail.MailAccount;
import cn.hutool.extra.mail.MailUtil;
import com.lxy.code.service.SendCodeByEmailService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Value;

/**
 * @author 123
 * @date 2020/6/22 18:36
 * @description
 */
@Service
public class SendCodeByEmialServiceImpl implements SendCodeByEmailService {

    @Value("${email.host}")
    private String host;
    @Value("${email.port}")
    private int port;
    @Value("${email.from}")
    private String from;
    @Value("${email.password}")
    private String password;

    @Override
    public Boolean sendCode(String email,String code) {
        return sendEmailCode(email,code);
    }


    private Boolean sendEmailCode(String email,String code){
        MailAccount account = new MailAccount();
        account.setHost(host);
        account.setPort(port);
        account.setAuth(true);
        account.setFrom(from);
        account.setUser(from);
        account.setPass(password); //密码
        MailUtil.send(account,email, "邮箱验证码",code, false);
        return true;
    }



}
